home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3523 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: camelot.dsccc.com!not-for-mail
  2. From: kcline@sun132.spd.dsccc.com (Kevin Cline)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Abend caused by "strcmp"
  5. Date: 24 Jan 1996 10:45:00 -0600
  6. Organization: DSC Communications Corporation Switch Products Division
  7. Message-ID: <4e5nmc$ru9@sun132.spd.dsccc.com>
  8. References: <4e4guc$o1u@tst.hk.super.net> <4e5n7c$rdm@sun132.spd.dsccc.com>
  9. NNTP-Posting-Host: sun132.spd.dsccc.com
  10.  
  11. In article <4e4guc$o1u@tst.hk.super.net>,
  12. Judy Wong  <jlcwong@hk.super.net> wrote:
  13.  >I am using Borland C++ v4.0 & v4.5.  My machine is Intel Pentium 100.  
  14.  >The program I wrote is a window program.
  15.  >
  16.  >In v4.5, when my program executes the statement :
  17.  >
  18.  >   "if (strcmp(a, NULL) == 0) ..." where a is declared as
  19.  >                                         char *a="name";
  20.  >
  21.  >it abends with the following 'Unhandled Exception' error msg. :
  22.  
  23. Only IBM mainframe programs "abend".  PC programs crash. 
  24. Unix programs abort or dump core. 
  25.  
  26. Anyway, you can't pass NULL (0) to strcmp; you must pass a pointer to
  27. an actual string.  I can't tell whether you are trying to tell whether
  28. a points to an empty string, or whether a is a null pointer.  To
  29. determine if a points to an empty string:
  30.     if (*a == 0)    // If first char is 0 
  31. or
  32.     if (!*a)    // some like this style, some don't.
  33.  
  34. To determine if a is a null pointer:
  35.     if (a == 0)
  36. or
  37.     if (!a)        // some like this style, some don't.  
  38.  
  39. Do not use NULL in C++ programs; just use zero instead.  You will also
  40. simplify your life if you can get a string class and use it instead of
  41. pointers to char.  
  42. --
  43. Kevin Cline
  44.  
  45.  
  46. -- 
  47. Kevin Cline
  48.